package com.jt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jt.dto.UserPageDto;
import com.jt.mapper.RouterMapper;
import com.jt.mapper.UserMapper;
import com.jt.pojo.Router;
import com.jt.pojo.User;
import com.jt.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.boon.primitive.Arry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RouterMapper routerMapper;

    @Override
    public List<User> selectAllUserList() {
        return userMapper.selectList(null);
    }


    @Override
    public User selectByNameAndPassWorld(String name, String passWold) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        queryWrapper.eq("passWold", passWold);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public boolean insert(User user) {
        user.setDeleteType("0");
        int count = userMapper.insert(user);
        if (count > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public List<User> UserPageList(UserPageDto userPageDto) {
        return userMapper.UserPageList(userPageDto);
    }

    @Override
    public int UserTotal(UserPageDto userPageDto) {
        return userMapper.UserTotal(userPageDto);
    }

    @Override
    public boolean AssignPermissions(String userId, String roleId) {
        return   userMapper.AssignPermissions(userId,roleId);
    }
}
